/*
 * 2014-11-29 <br/>
 * 
 */
package cn.bs.base.dao.impl;

import cn.bs.base.dao.IBaseDao;
import cn.bs.base.eo.ABaseEO;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.io.Serializable;
@Repository("baseDao")
public class BaseDao<T extends ABaseEO> implements IBaseDao<T>{
    @Resource
    private SessionFactory sessionFactory;

    public Session getCurrentSession() {
        return sessionFactory.getCurrentSession();
    }
    @Override
    public Serializable save(T t) {
        return getCurrentSession().save(t);
    }

    @Override
    public T getEO(Class<?> t, Serializable id) {
        return (T)getCurrentSession().get(t, id);
    }

    @Override
    public void deleteEO(Class<?> t, Serializable id) {
        getCurrentSession().delete(getEO(t,id));
    }
}
